package org.nf.sms.test;

import org.nf.sms.dao.StaffDao;
import org.nf.sms.dao.impl.StaffDaoImpl4DbUtil;
import org.nf.sms.dao.impl.StaffDaoImpl4Jdbc;
import org.nf.sms.entity.Staff;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author zqx
 * @Date 2024-03-08
 */
public class StaffDaoTest02 {
    /**
     * 测试分页查询
     */
    private static void testSelectByPage() {
        // 多态
        StaffDao staffDao = new StaffDaoImpl4DbUtil();

        // 当前页
        int currentPage = 1;
        // 每页记录数
        int count = 2;

        int limit = (currentPage - 1) * count;

        List<Staff> list = staffDao.selectByPage(limit, count);

        // JDK8新语法
        list.stream().forEach(System.out::println);
    }

    /**
     * 测试修改操作
     */
    private static void testUpdate() {
        Staff s = new Staff();
        s.setName("张三");
        s.setAge(18);
        s.setStaPos("项目组长");
        s.setPhone("13417747370");
        s.setUpdateTime(LocalDateTime.now());
        s.setId(1);

        StaffDao staffDao = new StaffDaoImpl4DbUtil();
        int row = staffDao.update(s);
        System.out.println(row);
    }

    private static void testDelete() {
        StaffDao staffDao = new StaffDaoImpl4DbUtil();
        int row = staffDao.delete(1);
        System.out.println(row);
    }

    private static void testAdd() {
        Staff s = new Staff();
        s.setName("张三三");
        s.setAge(28);
        s.setStaPos("项目经理");
        s.setPhone("13417747371");

        StaffDao staffDao = new StaffDaoImpl4DbUtil();
        int row = staffDao.insert(s);
        System.out.println(row);
    }

    private static void testSelectById() {
        StaffDao staffDao = new StaffDaoImpl4DbUtil();
        Staff staff = staffDao.selectById(4);
        System.out.println(staff);
    }

    private static void testSelectTotalCount() {
        StaffDao staffDao = new StaffDaoImpl4DbUtil();
        System.out.println(staffDao.selectTotalCount());
    }

    public static void main(String[] args) {
        // testSelectByPage();
        // testUpdate();
        //testDelete() ;
        // testAdd();
        // testSelectById() ;
        testSelectTotalCount() ;
    }
}
